package com.lovely3x.library.wxapi;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.lovely3x.common.activities.CommonActivity;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.handler.UMWXHandler;
import com.umeng.socialize.weixin.view.WXCallbackActivity;

/**
 * 微信入口界面
 * Created by ntop on 15/9/4.
 */
public class WXEntryActivity extends CommonActivity implements IWXAPIEventHandler {

    private final String TAG = WXCallbackActivity.class.getSimpleName();
    protected UMWXHandler mWxHandler = null;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        UMShareAPI api = UMShareAPI.get(this.getApplicationContext());
        this.mWxHandler = (UMWXHandler) api.getHandler(SHARE_MEDIA.WEIXIN);
        this.mWxHandler.onCreate(this.getApplicationContext(), PlatformConfig.getPlatform(SHARE_MEDIA.WEIXIN));
        this.mWxHandler.getWXApi().handleIntent(this.getIntent(), this);
    }

    protected final void onNewIntent(Intent paramIntent) {
        Log.d(this.TAG, "### WXCallbackActivity   onNewIntent");
        super.onNewIntent(paramIntent);
        this.setIntent(paramIntent);
        UMShareAPI api = UMShareAPI.get(this.getApplicationContext());
        this.mWxHandler = (UMWXHandler) api.getHandler(SHARE_MEDIA.WEIXIN);
        this.mWxHandler.onCreate(this.getApplicationContext(), PlatformConfig.getPlatform(SHARE_MEDIA.WEIXIN));
        this.mWxHandler.getWXApi().handleIntent(paramIntent, this);
    }

    public void onResp(BaseResp resp) {
        if (this.mWxHandler != null && resp != null) {
            try {
                this.mWxHandler.getWXEventHandler().onResp(resp);
            } catch (Exception var3) {

            }
        }

        this.finish();
    }

    public void onReq(BaseReq req) {
        if (this.mWxHandler != null) {
            this.mWxHandler.getWXEventHandler().onReq(req);
        }
        this.finish();
    }

    @Override
    public void applyTranslationStatusBarAndNavigationBar(boolean showStatusBar, boolean showNavigationBar, int statusBarColor, int navigationBarColor,boolean tint,boolean darkMode) {

    }

    @Override
    public void applyTranslationStatusBarAndNavigationBar(Tint tint) {

    }
}
